package com.paipai.mq;

import com.paipai.entity.Round;
import com.paipai.utils.JsonUtils;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.Date;

@Component
public class StartRoundListner {

    @RabbitListener(queues = "scheduledStartRoundDeletterQueue")
    public void onMsg(Message message, Channel channel) throws IOException {
        try {
            Round round = JsonUtils.toObj(String.valueOf(message.getBody()), Round.class);
            System.out.println("当前时间：" + new Date().toString() + "消费" + new String(message.getBody()));
            //开启拍卖场代码

            //手动ack
            channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
        } catch (IOException e) {
            // e.printStackTrace();
            //如果异常 重新入队
            channel.basicNack(message.getMessageProperties().getDeliveryTag(),false,true);
        }
    }


}
